home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bc_ti.zip / TI651.ASC < prev    next >
Text File  |  1992-02-25  |  1KB  |  67 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  C++                                    NUMBER  :  651
  9.   VERSION  :  All
  10.        OS  :  PC DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/1
  12.  
  13.     TITLE  :  Initializing Static Class Members of Type Class
  14.  
  15.  
  16.  
  17.  
  18.   /* IMPORTANT! When testing static member initialization, you must
  19.      declare an instance of the class in a main function; otherwise, the
  20.      linker has no reference which it must try to resolve, and the
  21.      undefined symbol error will not be seen--thus you won't know that
  22.      your initialization was in error.
  23.   */
  24.  
  25.   //declare a class
  26.   class First {
  27.     public:
  28.       int count;
  29.       First() {}  //must have callable constructor
  30.   };
  31.  
  32.   //declare class containing static member of class First
  33.   class Second {
  34.     public:
  35.       static First fVar;
  36.   };
  37.  
  38.   //initialize static member of class Second
  39.   First Second::fVar = First();  //initialize with explicit call to ctor
  40.  
  41.   int main(void)
  42.   {
  43.     Second *sVarA = new Second;
  44.     delete sVarA;
  45.     return 0;
  46.   }
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.